Skip to content

Conversation

LostKobrakai
Copy link
Contributor

@LostKobrakai LostKobrakai commented Sep 27, 2017

Regarding #779.

By now I've just added grouping for modules. I can add the changes for the grouping of pages at a later time. Also I'm not sure where/how to test the changes to ExDoc.Formatter.HTML.Templates.

Also:
Damn is it nice to use it even just for the following groups in phoenix projects.

[
          "Web - Controllers": ~R/^MyAppWeb\..*?Controller$/,
          "Web - Views": ~R/^MyAppWeb\..*?View$/,
          "Web - Plugs": ~R/^MyAppWeb\..*?Plug$/,
          "Web - Phoenix": ~R/^MyAppWeb.?/
]

@@ -0,0 +1,2 @@
defmodule GroupedImplicitlyRegex do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modules should have a @moduledoc tag.

@@ -0,0 +1,2 @@
defmodule GroupedExplicitlyString do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modules should have a @moduledoc tag.

@@ -0,0 +1,2 @@
defmodule GroupedExplicitlyAtom do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modules should have a @moduledoc tag.

files = Enum.map names, fn(n) -> "test/tmp/Elixir.#{n}.beam" end
config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!}
config = %ExDoc.Config{
source_url_pattern: url_pattern,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

[module_node] = docs_from_files ["CompiledWithDocs"]
assert module_node.module == CompiledWithDocs
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.


defp module_group(module, group_patterns) do
group_patterns
|> Enum.find_value(fn {group, patterns} ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a function call when a pipeline is only one function long


defstruct id: nil, title: nil, module: nil, doc: nil, doc_line: nil,
docs: [], typespecs: [], source_path: nil, source_url: nil, type: nil
defstruct id: nil, title: nil, module: nil, group: nil, doc: nil,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

defstruct id: nil, title: nil, module: nil, doc: nil, doc_line: nil,
docs: [], typespecs: [], source_path: nil, source_url: nil, type: nil
defstruct id: nil, title: nil, module: nil, group: nil, doc: nil,
doc_line: nil, docs: [], typespecs: [], source_path: nil,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.


defp module_group(module, group_patterns) do
group_patterns
|> Enum.find_value(fn {group, patterns} ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

defp module_in_patterns(module, patterns) do
"Elixir." <> module_string = Atom.to_string module

Enum.any?(patterns, fn pattern ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

@LostKobrakai LostKobrakai force-pushed the feature/module_grouping branch from 40dcf34 to 9fbdde0 Compare September 27, 2017 09:24
assert functions == ["plus_one/1", "plus_two/1"]
end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a final \n at the end of each file.

@LostKobrakai LostKobrakai force-pushed the feature/module_grouping branch from 9fbdde0 to 5fe54cd Compare September 27, 2017 09:25
@LostKobrakai LostKobrakai force-pushed the feature/module_grouping branch from 5fe54cd to a59e346 Compare September 27, 2017 09:27
|> Enum.map(&get_module(&1, config))
|> Enum.filter(&(&1))
|> Enum.sort(&(&1.id <= &2.id))
|> Enum.sort_by(&({&1.group, &1.id}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should order them by the group index in module_groups. So the first group will be first, etc. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By now order was alphabetically by module name, so I feel like having groups sorted alphabetically isn't to bad. Also if you look at the example above in the PR description I've used a less strict regex as last group to catch all phoenix related modules, which weren't caught by the more precise earlier ones. So the order of groups might be useful for "catch-all" cases more so than for sorting order of the groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But looking at the way groups worked with pages before, they are ordered by the order of first occurrence of a group, which might be a needed feature. Especially if we make the setup of both the same and deprecate the old way of grouping pages we should look out for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But looking at the way groups worked with pages before, they are ordered by the order of first occurrence of a group, which might be a needed feature.

Yup, precisely.

Plus if we give them control, they can keep it alphabetically. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really like to retain the user-defined "order of matching" as well, because otherwise the regex patterns might have to be more complex in places. Anything like "group all the remaining modules starting with MyAppWeb" won't be easy if the order in the list does determine the frontend order instead of the matching order. Having a regex exclude the matches of possibly multiple regexes can be quite a pain.

But maybe that's a topic for a later enhancement to the implementation.

end

defp module_in_patterns(module, patterns) do
"Elixir." <> module_string = Atom.to_string module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not assume the module name is "Elixir." because of Erlang modules. You should probably use the module id or title.

case pattern do
%Regex{} = regex -> Regex.match?(regex, module_string)
string when is_binary(string) -> module_string === string
atom -> atom === module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use == and above. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly do this. I'm just curious, how would/should one decide between == and ===?

@@ -0,0 +1,3 @@
defmodule GroupedExplicitlyAtom do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to define new features. You can use the existing features and instead change the configuration every time you generate the docs. This can probably be done by changing this function to receive a keyword list that is merged into ExDoc.Config. then you just pass the module groups.

@josevalim
Copy link
Member

@LostKobrakai this looks really nice, I have added some comments. Regarding the templates tests, a unit test will suffice for now, just set the group manually.

config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!}
config =
%ExDoc.Config{source_url_pattern: "http://example.com/%{path}#L%{line}", source_root: File.cwd!}
|> struct(config)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a function call when a pipeline is only one function long

defp docs_from_files(names, config \\ []) do
files = Enum.map names, fn(n) -> "test/tmp/Elixir.#{n}.beam" end
config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!}
config =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

source_url: source_url(),
output: "test/tmp/html_templates"
}
|> struct(config)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a function call when a pipeline is only one function long

assert content =~ ~r("id":"CompiledWithDocs".*"functions":.*"example_without_docs/0")ms
assert content =~ ~r("id":"CompiledWithDocs.Nested")ms
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

assert "Group" == match_module(patterns, :lists, ":lists")
assert nil == match_module(patterns, MyApp.SomeOtherModule, "MyApp.SomeOtherModule")
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

assert nil == match_extra(patterns, "docs/introduction.md")
end
end
end No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a final \n at the end of each file.

content = read_wildcard!("#{output_dir()}/dist/sidebar_items-*.js")
assert content =~ ~r{"id":"readme","title":"README","group":"Intro"}
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

end
end)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no trailing white-space at the end of a line.

defp match_patterns(patterns, matcher) do
Enum.any?(patterns, matcher) || nil
end
end No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a final \n at the end of each file.

end

defp build_extra(input, id, title, group, project_nodes, extension) do
defp build_extra(input, id, title, group, project_nodes, extension, config) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function takes too many parameters (arity is 7, max is 5).

@LostKobrakai LostKobrakai force-pushed the feature/module_grouping branch from 7ada3c5 to 41d299a Compare September 28, 2017 19:11
@josevalim josevalim merged commit 9d571f0 into elixir-lang:master Sep 30, 2017
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants